<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>array</title>
</head>
<body>
    <script>
        {

            // 数组的平方 [1,2,3,4,5] -> [1, 2, 3, 4, 5, 1, 4, 9, 16, 25]

            let a = [1,2,3,4,5];

            // 关键就是这个步骤
            Array.prototype.mutiply = function () {
                let b = this.map((ele)=>{
                    return ele*ele
                })
                return this.concat(b)
            }

            a.mutiply();

            console.log('第一题',a.mutiply());
        }

        {
            // 元素递增数组

            let a = [];
            for(let i=1;i<101;i++){
                a.push(i);
            }
            console.log('第二题',a);
        }

        {

            //  打平嵌套数组 [1, [2, [3], 4], 5] => [1, 2, 3, 4, 5]

            let ary = [1, [2, [3], 4], [5,6,7],8];

            function flattenAry (ary) {
                let a = ary.toString().split(',');
                return a.map(Number);
            }

            console.log(flattenAry(ary));

        }

        
    </script>
</body>
</html>